package com.bua.control;

import android.content.Context;
import android.widget.Button;
import android.util.AttributeSet;
import android.view.View;

public class MultipleCheckButton extends Button {

	private Context mContext = null;
	private MultipleAlert multiplAlert = null;
	public String[] items;
	public boolean[] checked;
	private String checkedString;

	public MultipleCheckButton(Context context) {
		super(context);
		mContext = context;
		this.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ShowCheckList();
			}
		});
		// TODO Auto-generated constructor stub

	}

	public MultipleCheckButton(Context context, AttributeSet attrs) {
		super(context, attrs);

		mContext = context;
		this.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ShowCheckList();
			}
		});
	}

	public MultipleCheckButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);

		mContext = context;
		this.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ShowCheckList();
			}
		});
	}

	public void SetItems(String[] itemArray) {
		items = itemArray;
		checked = new boolean[itemArray.length];
	}

	public String GetTitle() {
		return this.getText().toString();
	}

	public void UpdateTitle() {
		checkedString = "";

		for (int index = 0; index < items.length; index++) {
			if (checked[index])
				checkedString += items[index] + "\r\n";
		}
		if (checkedString.length() > 0)
			checkedString = checkedString.substring(0,
					checkedString.length() - 1);

		this.setText(checkedString);
	}

	public void SetItemChecked(int index, boolean isChecked) {
		checked[index] = isChecked;
	}

	public void ShowCheckList() {
		multiplAlert = new MultipleAlert(mContext, this);
		multiplAlert.Show();
	}

	public String GetSelectedList() {
		return checkedString;
	}
}
